// 静态多态

#include <iostream>
using namespace std;

template <typename T>
class Base {
    friend T;
private:
    // prevent this kind of hierarchy
    // class Derived2 : public Base<Derived>
    Base(){}; 
    
public:
    void interface()
    {
        static_cast<T*>(this)->implementation();
    }
};

struct Derived : Base<Derived>
{
    void implementation()
    {
        cerr << "Derived implementation\n";
    }
};

int main()
{
    Derived d;
    d.interface();  // Prints "Derived implementation"
    
    return 0;
}
